﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Linq;
using Microsoft.SharePoint;

namespace Expertime.Multitude.Intranet.Utils
{
    class SPListItemPlanActionUtility : SPListItemElementUtility
    {
        #region Constants
        public const String LIST_DEMANDES = "Demandes";
        public const String LIST_PROCESSUS = "Processus";
        public const String LIST_PLANS_ACTIONS = "Plans d\'actions";
        public const String LIST_ACTIONS = "Actions";

        public const String FIELD_DEMANDES_PROCESSUS = "Processus";
        public const String FIELD_DEMANDES_ETAT = "Etat";
        public const String FIELD_DEMANDES_COMMENTAIRES = "Commentaires";
        public const String FIELD_DEMANDES_INFORMATIONS = "Informations";
        public const String FIELD_DEMANDES_CLOTURE = "Cloture";
        public const String FIELD_DEMANDES_PLAN_ACTIONS = "Plan_x0020_d_x0027_actions";
        public const String FIELD_DEMANDES_RESPONSABLE = "Responsable";
        public const String FIELD_DEMANDES_ARBITRAGE = "Arbitrage";

        public const String FIELD_PLANS_RESPONSABLE = "Responsable";
        public const String FIELD_PLANS_RESPONSABLE_PROCESSUS = "ResponsableProcessus";
        public const String FIELD_PLANS_INFORMATIONS = "Informations";
        public const String FIELD_PLANS_PROCESSUS = "Processus";

        public const String FIELD_ACTIONS_PLAN_ACTIONS = "Plan_x0020_d_x0027_actions";
        public const String FIELD_ACTIONS_CONTENU_ASSOCIE = "Contenu associé";

        #endregion Constants

        #region Methods

        public static DemandesÉlément GetDemandeByID(string webUrl, int id)
        {
            // Get DataContext from page context
            DataContext data = new DataContext(webUrl);

            // Get the SharePoint list
            EntityList<DemandesÉlément> demandesList = data.GetList<DemandesÉlément>(LIST_DEMANDES);

            // Query for customers from London
            var demandes = from demande in demandesList
                            where demande.ID == id
                            select demande;

            return demandes.Count() > 0 ? demandes.First() : null;
        }
        public static DemandesÉlément GetDemandeByTitle(string webUrl, string title)
        {
            // Get DataContext from page context
            DataContext data = new DataContext(webUrl);

            // Get the SharePoint list
            EntityList<DemandesÉlément> demandesList = data.GetList<DemandesÉlément>(LIST_DEMANDES);

            // Query for customers from London
            var selectedDemandes = from demande in demandesList
                           where demande.Titre == title
                           select demande;

            return selectedDemandes.Count() > 0 ? selectedDemandes.First() : null;
        }

        public static ProcessusÉlément GetProcessusByTitle(string webUrl, string title)
        {
            // Get DataContext from page context
            DataContext data = new DataContext(webUrl);

            // Get the SharePoint list
            EntityList<ProcessusÉlément> processusList = data.GetList<ProcessusÉlément>(LIST_PROCESSUS);

            // Query for customers from London
            var selectedProcessus = from processus in processusList
                            where processus.Titre == title
                            select processus;

            return selectedProcessus.Count() > 0 ? selectedProcessus.First() : null;
        }
        public static ProcessusÉlément GetProcessusByID(string webUrl, int id)
        {
            // Get DataContext from page context
            DataContext data = new DataContext(webUrl);

            // Get the SharePoint list
            EntityList<ProcessusÉlément> processusList = data.GetList<ProcessusÉlément>(LIST_PROCESSUS);

            // Query for customers from London
            var selectedProcessus = from processus in processusList
                                    where processus.ID == id
                                    select processus;

            return selectedProcessus.Count() > 0 ? selectedProcessus.First() : null;
        }

        #endregion Methods
    }
}
